<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!-- 定义项目路径   url标签可以  -->
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>伊翔分销平台-注册</title>

<style type="text/css">
.u_logo{margin: 12px 0 24px;}
.u_logo a{}
.u_logo a img{ border:0;}
.mod-bread {background: url("${ctx }/jslib/regvalid/img/breadbg.gif") repeat-x scroll 0 0 transparent;height: 46px;}
.mod-bread .bread-left {float: left;font-size: 14px;font-weight: bold;height: 46px;line-height: 46px;text-align: right;width: 137px;}
.mod-bread .bread-right {float: right;height: 46px;line-height: 46px;padding-right: 20px;}
</style>
<!-- 引入jQuery -->
<script src="${ctx}/jslib/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
<!-- 引入layer -->
<script src="${ctx}/jslib/layer/layer.js" type="text/javascript" charset="utf-8"></script>
<!-- 引入EasyUI -->
<link id="easyuiTheme" rel="stylesheet" href="${ctx}/jslib/easyui1.3.3/themes/<c:out value="${cookie.easyuiThemeName.value}" default="default"/>/easyui.css" type="text/css">
<link id="easyuiTheme" rel="stylesheet" href="${ctx}/jslib/easyui1.3.3/themes/icon.css" type="text/css">
<script type="text/javascript" src="${ctx}/jslib/easyui1.3.3/jquery.easyui.min.js" charset="utf-8"></script>
<script type="text/javascript" src="${ctx}/jslib/easyui1.3.3/locale/easyui-lang-zh_CN.js" charset="utf-8"></script>
<!-- 扩展Jquery -->
<script type="text/javascript" src="${ctx}/jslib/extJquery.js" charset="utf-8"></script>

<link href="${ctx }/jslib/regvalid/main.css" rel="stylesheet" type="text/css" />
<!--必要样式-->
<link href="${ctx }/jslib/regvalid/user_form.css" rel="stylesheet" type="text/css" />
<script src="${ctx }/jslib/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript" src="${ctx }/jslib/cityselect/js/jquery.cityselect.js"></script>
<script src="${ctx }/jslib/regvalid/formValidator-4.1.1.js" type="text/javascript"></script>
<script src="${ctx }/jslib/regvalid/formValidatorRegex.js" type="text/javascript"></script>
<script type="text/javascript">
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
function closeWin(){
	 parent.layer.close(index);
}
$(document).ready(function(){
	$("#city_3").citySelect({nodata:"none",required:false});
	$.formValidator.initConfig({theme:"baidu",mode:"AutoTip",submitOnce:true,formID:"user_form_0",
		submitAfterAjaxPrompt : '有数据正在异步验证，请稍等...'
	});
	$("#username").formValidator({onShowText:"请输入用户名",onFocus:"6~12个字符，包括字母、数字、下划线，以字母开头，字母或数字结尾",onCorrect:"该用户名可以注册",tipCss:{height:36,width:460}}).inputValidator({min:6,max:12,onError:"你输入的用户长度不正确,请确认"}).regexValidator({regExp:"username",dataType:"enum",onError:"用户名格式不正确"})
	    .ajaxValidator({
		dataType : "json",
		async : true,
		url : "${ctx}/user/checkUser",
		success : function(data){
            if( data.success) return true;
            if( !data.success) return false;
			return false;
		},
		buttons: $("#user_submit"),
		error: function(jqXHR, textStatus, errorThrown){alert("服务器没有返回数据，可能服务器忙，请重试"+errorThrown);},
		onError : "该用户名不可用，请更换用户名",
		onWait : "正在进行合法性校验，请稍候..."
	});
	
	$("#nickname").formValidator({onShowText:"请输入昵称",onFocus:"必须为汉字、英文字母、数字、不包含特殊字符",onCorrect:"输入正确",tipCss:{height:36,width:320}}).inputValidator({min:1,max:20,onError:"输入的长度不正确"}).regexValidator({regExp:"company",dataType:"enum",onError:"格式不正确"});
	$("#mobile").formValidator({onShowText:"请输入联系人手机",onFocus:"请输入手机号方便找回密码",onCorrect:"输入正确",tipCss:{height:36,width:320}}).inputValidator({min:1,max:50,onError:"输入的长度不正确"}).regexValidator({regExp:"mobile",dataType:"enum",onError:"格式不正确"});
	$("#mail").formValidator({onShowText:"请输入邮箱",onFocus:"请输入常用邮箱，通过验证后可用于登陆和找回密码",defaultValue:"@",tipCss:{height:36,width:320}}).inputValidator({min:6,max:60,onError:"请输入邮箱"}).regexValidator({regExp:"email",dataType:"enum",onError:"邮箱格式不正确"});
	
	$.formValidator.reloadAutoTip(); 
	  var ajaxFormOption = {
           type: "post",  //提交方式  
           dataType: "json", //数据类型  
           url: "${ctx}/user/operatorAdd", //请求url  
           success: function (data) { //提交成功的回调函数  
        	  progressClose();
           	  if(data.success){
           		layer.alert('营业员添加成功！',{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
        		  	$("#user_form_0")[0].reset();  
        		  	closeWin();
				    layer.close(index);
				});
           	  }else{
           		layer.alert(data.msg,{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
				    layer.close(index);
				});
           	  }
           },
           error:function(){
        	   progressClose();
           }
       };
	  //不需要submit按钮，可以是任何元素的click事件
       $("#user_submit").click(function () {
    	   var temp = $.formValidator.pageIsValid("1");
    	   if(temp){
    		   progressLoad();
    		   $("#user_form_0").ajaxSubmit(ajaxFormOption);
    	   }
           return false;
       });
});
</script>
</head>

<body>

<div class="div" style="padding-top:20px;">
<form id="user_form_0" class="user_form" method="post" action="${ctx }/user/reg">
<p>
<label id="label_username" for="username">用户名</label>
<input id="username" class="user_input" type="text" name="username" >
</p>

<p>
<label id="label_username" for="username">姓名</label>
<input id="nickname" class="user_input" type="text" name="nickname" >
</p>

<p>
<label id="label_password_0" for="password_0">密码</label>
<input id="pwd" class="user_input" type="text" name="pwd" readonly="readonly" value="888888">
</p>

<p>
<label id="label_city" for="mobile">手机</label>
<input id="mobile" class="user_input" type="text" name="mobile">
</p>
 
<p>
<label id="label_mail" for="mail">邮箱</label>
<input id="mail" class="user_input" type="text" name="mail">
</p>
 
<div class="clear"></div>
<p>
<input name="提交" type="button" class="user_submit" id="user_submit" style="margin-left:152px;"  value="添加">
</p>
</form>

</div>
</body>
</html>
